package com.arzaguet.pueblobelen;

import com.google.ads.*;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PuebloBelen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  
        setContentView(R.layout.main);
        
        WebView myWebView = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
      //para abrir los link en el mismo webview
        myWebView.setWebViewClient(new WebViewClient()); 
        myWebView.loadUrl("http://www.pueblobelen.arzaguet.com");
        
        // Look up the AdView as a resource and load a request.
        AdView layout = (AdView)this.findViewById(R.id.adView);
        
        // Initiate a generic request to load it with an ad
        AdRequest adRequest = new AdRequest();
        adRequest.setTesting(false);
        
        layout.loadAd(adRequest);                 
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // chequea que se a apretado la tecla retorno
    	WebView myWebView = (WebView) findViewById(R.id.webView1);
        if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
            myWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
  
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.pueblo_menu, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	abrirDialogo();
        return super.onOptionsItemSelected(item);
    }
    
    public void abrirDialogo(){
    	AlertDialog.Builder builder = new AlertDialog.Builder(this);
    	builder.setMessage("www.arzaguet.com - Eclipse Public License - v 1.0 - 2011")
    	       .setCancelable(false)
    	       .setNegativeButton("Ok", new DialogInterface.OnClickListener() {
    	           public void onClick(DialogInterface dialog, int id) {
    	                dialog.cancel();
    	           }
    	       });
    	AlertDialog alert = builder.create();
    	alert.show();
    }
}